﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Okuma.CLDATAPI.DataAPI;
using Okuma.CLDATAPI.Enumerations;
using OpenNETCF.MTConnect;

namespace Okuma
{
    public class Spindle : ToolPart
    {
        private CSpindle m_spindle;

        internal Spindle(SubSystemEnum subSystem)
            : base(subSystem)
        {
            m_spindle = new CSpindle(subSystem);
        }

        public override string Name
        {
            get { return "Spindle"; }
        }

        public override ComponentType ComponentType
        {
            get { return ComponentType.Rotary;  }
        }

        [SampleDataItem(UnitValues.MillimiterPerSecond, // TODO: verify this
            ItemType = DataItemType.ROTARY_VELOCITY)]
        public int ActualRate
        {
            get { return m_spindle.GetActualSpindlerate(); }
        }

        [SampleDataItem(UnitValues.MillimiterPerSecond, // TODO: verify this
            ItemType = DataItemType.ROTARY_VELOCITY)]
        public int CommandRate
        {
            get { return m_spindle.GetCommandSpindlerate(); }
        }

        [SampleDataItem(UnitValues.MillimiterPerSecond, // TODO: verify this
            ItemType = DataItemType.ROTARY_VELOCITY)]
        public int SurfaceSpeed
        {
            get { return m_spindle.GetSpindleSurfaceSpeed(); }
        }

        [SampleDataItem(UnitValues.Percent, // TODO: verify this
            ItemType = DataItemType.LOAD)]
        public int Load
        {
            get { return m_spindle.GetSpindleLoad(); }
        }

        [EventDataItem(
            ItemType = DataItemType.DIRECTION)]
        public string State
        {
            get 
            {
                var state = m_spindle.GetSpindleState();
                switch (state)
                {
                    case SpindleStateEnum.CCW:
                        return "COUNTER_CLOCKWISE";
                    case SpindleStateEnum.CW:
                        return "CLOCKWISE";
                    case SpindleStateEnum.Stop:
                        return "STOPPED";
                    case SpindleStateEnum.Indexing:
                        return "INDEXING";
                }

                return string.Empty;
            }
        }

        [EventDataItem]
        public string CurrentSelection
        {
            get { return m_spindle.GetCurrentSpindleSelection().ToString(); }
        }

    }
}
